package edu.csumb.itcd.teammario;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

public class IntroPanel extends JPanel implements Runnable, MouseListener {

	private Thread introThread;
	private int selectorPosition;
	private boolean play;
	
	public IntroPanel()
	{
		this.setBounds(-1, -1, 800, 600);
		selectorPosition = 350;
		this.setFont(new Font("Comic Sans MS", Font.PLAIN, 48));
		this.setBackground(Color.white);
		introThread = new Thread(this);
		introThread.start();
		addMouseListener(this);
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (true)
		{
			if (Setup.getPlay() == false)
			{
				if (this.getMousePosition() != null && this.getMousePosition().y < 425)
				{
					selectorPosition = 350;
					play = true;
				} else
				{
					selectorPosition = 445;
					play = false;
				}
				
				repaint();
			}
			
			try {
				Thread.sleep(30);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		g.drawString("Team Mario Game", 200, 200);
		g.setColor(Color.green);
		g.fillRect(320, selectorPosition, 150, 75);
		g.setColor(Color.black);
		g.drawString("Play", 350, 400);
		g.drawString("Exit", 350, 500);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		if (Setup.getPlay() == false)
		{
			if (play)
			{
				Setup.setPlay(true);
			} else
			{
				System.exit(0);
			}
		}
	}
}
